/**
 * Created by GeYingJie on 2023/05/10.
 */
const fileTypes = [
  { img: 'doc.png', types: ['doc', 'docx', 'docm'] },
  { img: 'xlsx.png', types: ['xls', 'xlsx', 'xlsm'] },
  { img: 'ppt.png', types: ['ppt', 'pptx', 'pptm'] },
  { img: 'pdf.png', types: ['pdf'] },
];
const unknownType = 'unknown.png';
/**
 * 
 * @param {string} filename 
 * @returns {resolve || reject}
 */
function GetFileTypeIMG(filename) {
  return new Promise((resolve) => {
    var nIndex = filename ? filename.lastIndexOf(".") : -1;
    if (nIndex !== -1) {
      var filetype = filename.substring(nIndex + 1).toLowerCase();
      if (fileTypes[filetype]) resolve("document");
      var obj = fileTypes.find(e => e.types.indexOf(filetype) > -1);
      if (obj) resolve(obj.img);
      resolve(unknownType);
    } else {
      resolve(unknownType);
    }
  });
}